#include "key_4x4.h"
void key_enable(){
  DDRC=0xf0;
  asm volatile ("nop");
  key_on;
}
void key_disable(){
  DDRC=0xff;
  key_off;	
}

uint8_t key_read(){
  uint8_t num;
  key_enable();
  while ( !( PINB & (1 << PB1)) );//control antirebote
  while ( PINB & ( 1<<PB1 ) ) ;
  num=  PINC & 0x0F;//solo se toman los primeros 4 bits 
                    //del puerto C
  asm volatile ("nop");
  key_disable();
  switch(num){
  case 0: return 0x31;//return 1
  case 1: return 0x32;//return 2
  case 2: return 0x33;//return 3
  case 3: return 0x41;//return A
  case 4: return 0x34;//return 4
  case 5: return 0x35;//return 5
  case 6: return 0x36;//return 6
  case 7: return 0x42;//return B
  case 8: return 0x37;//return 7
  case 9: return 0x38;//retun 8
  case 10:return 0x39;//return 9 
  case 11:return 0x43;//return C
  case 12:return 0x2A;// return *
  case 13:return 0x30;//return 0
  case 14:return 0x23;//return #
  case 15:return 0x44;//return D
  default: return 0x55;//return U
  }
}	




